import 'package:flutter/material.dart';
import '../theme/theme.dart';

/// 顶部导航栏组件
class SideTopNavBar extends StatelessWidget {
  /// 是否显示右侧边栏
  final bool showRightSidebar;
  
  /// 右侧边栏切换回调
  final VoidCallback onRightSidebarToggle;
  
  /// 菜单折叠状态
  final bool isCollapsed;
  
  /// 菜单折叠切换回调
  final VoidCallback onMenuCollapsedToggle;

  const SideTopNavBar({
    super.key,
    required this.showRightSidebar,
    required this.onRightSidebarToggle,
    required this.isCollapsed,
    required this.onMenuCollapsedToggle,
  });

  @override
  Widget build(BuildContext context) {
    final theme = HTheme.of(context);
    
    return Container(
      height: 50,
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            offset: const Offset(0, 1),
            blurRadius: 4,
          ),
        ],
      ),
      child: Row(
        children: [
          // 折叠按钮
          IconButton(
            icon: Icon(
              isCollapsed ? Icons.menu : Icons.menu_open,
              color: theme.colors.primary,
            ),
            onPressed: onMenuCollapsedToggle,
          ),
          
          // 搜索框
          Expanded(
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              child: TextField(
                decoration: InputDecoration(
                  hintText: '搜索...',
                  prefixIcon: Icon(Icons.search, color: theme.colors.textSecondary),
                  filled: true,
                  fillColor: theme.colors.background ?? Colors.grey[50],
                  contentPadding: EdgeInsets.zero,
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4),
                    borderSide: BorderSide.none,
                  ),
                ),
              ),
            ),
          ),
          
          // 通知图标
          _buildNotificationIcon(theme),
          
          // 消息图标
          _buildMessageIcon(theme),
          
          // 主题按钮
          IconButton(
            icon: Icon(Icons.palette, color: theme.colors.textSecondary),
            onPressed: onRightSidebarToggle,
          ),
          
          // 用户菜单
          _buildUserMenu(theme),
        ],
      ),
    );
  }
  
  /// 构建通知图标
  Widget _buildNotificationIcon(HTheme theme) {
    return Stack(
      alignment: Alignment.center,
      children: [
        IconButton(
          icon: Icon(Icons.notifications, color: theme.colors.textSecondary),
          onPressed: () {},
        ),
        Positioned(
          top: 8,
          right: 8,
          child: Container(
            padding: const EdgeInsets.all(2),
            decoration: BoxDecoration(
              color: Colors.red,
              borderRadius: BorderRadius.circular(10),
            ),
            constraints: const BoxConstraints(
              minWidth: 16,
              minHeight: 16,
            ),
            child: const Text(
              '8',
              style: TextStyle(
                color: Colors.white,
                fontSize: 10,
                fontWeight: FontWeight.bold,
              ),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ],
    );
  }
  
  /// 构建消息图标
  Widget _buildMessageIcon(HTheme theme) {
    return Stack(
      alignment: Alignment.center,
      children: [
        IconButton(
          icon: Icon(Icons.email, color: theme.colors.textSecondary),
          onPressed: () {},
        ),
        Positioned(
          top: 8,
          right: 8,
          child: Container(
            padding: const EdgeInsets.all(2),
            decoration: BoxDecoration(
              color: Colors.orange,
              borderRadius: BorderRadius.circular(10),
            ),
            constraints: const BoxConstraints(
              minWidth: 16,
              minHeight: 16,
            ),
            child: const Text(
              '16',
              style: TextStyle(
                color: Colors.white,
                fontSize: 10,
                fontWeight: FontWeight.bold,
              ),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ],
    );
  }
  
  /// 构建用户菜单
  Widget _buildUserMenu(HTheme theme) {
    return Container(
      margin: const EdgeInsets.only(right: 16),
      child: Row(
        children: [
          CircleAvatar(
            radius: 15,
            backgroundColor: theme.colors.primary.withOpacity(0.1),
            child: Icon(Icons.person, color: theme.colors.primary, size: 18),
          ),
          const SizedBox(width: 8),
          Text(
            '管理员',
            style: TextStyle(
              color: theme.colors.text,
              fontWeight: FontWeight.w500,
            ),
          ),
          const SizedBox(width: 4),
          Icon(Icons.arrow_drop_down, color: theme.colors.textSecondary),
        ],
      ),
    );
  }
} 